﻿@model CleverCMS.Cms.Services.ViewModels.PageEntryModel
@using CleverCMS.Cms.Data.Extensions

@section HeadContent{
}

@Html.Action("FreeHtml", "Tools", new { htmlKey = "Main_Right" })

<div @Html.Raw((User != null && User.IsInRole("Admin")) ? "contenteditable='true' id='editable-content'" : "") >
     @Html.Raw((Model).Page.PageContent)
</div>
<br />
<div class="row-fluid">
    <div class="span12">
        <b>Tags:&nbsp;&nbsp;</b> @Model.Page.Tags.ToTagString()
    </div>
</div>

@section Bottom
{
    @if (this.User.IsInRole("Admin"))
    {
        <script type="text/javascript">
            $(document).ready(function() {
                CKEDITOR.disableAutoInline = true;
                CKEDITOR.inline("editable-content", {
                    on: {
                        blur: function (event) {
                            var id = @Model.Page.Id;
                            var request = jQuery.ajax({
                                url: "@Url.Action("UpdateContent", "Page", new { area = "CleverCms.Admin" })",
                                type: "POST",
                                data: {
                                    content: event.editor.getData(),
                                    id: id
                                },
                                dataType: "html"
                            });

                        }
                    }
                });

                var editor = $("#editable-content");
                editor.css("border", "1px solid #4a8bc2");
                editor.before("<p style='color: #fff; background-color: #4a8bc2; padding: 5px; width: 220px; min-width: 210px; margin-bottom: 0px;'>Edit content</p>");
            });
        </script>
    }
}
